﻿
using BankerenClient.Events;
using Caliburn.Micro;
namespace BankerenClient
{
    public class HostGameViewModel : Screen, IMainScreen
    {
        #region Fields

        private string serverName;
        private bool allowSpectators;
        private bool allowCustomAvatars;
        private bool usePassword;
        private string password;

        #endregion

        #region Properties

        public string ServerName
        {
            get { return this.serverName; }
            set
            {
                this.serverName = value;
                NotifyOfPropertyChange(() => ServerName);
                NotifyOfPropertyChange(() => CanHostGame);
            }
        }

        public bool AllowSpectators
        {
            get { return this.allowSpectators; }
            set
            {
                this.allowSpectators = value;
                NotifyOfPropertyChange(() => AllowSpectators);
            }
        }

        public bool AllowCustomAvatars
        {
            get { return this.allowCustomAvatars; }
            set
            {
                this.allowCustomAvatars = value;
                NotifyOfPropertyChange(() => AllowCustomAvatars);
            }
        }

        public bool UsePassword
        {
            get { return this.usePassword; }
            set
            {
                this.usePassword = value;
                NotifyOfPropertyChange(() => UsePassword);
                NotifyOfPropertyChange(() => CanHostGame);
            }
        }

        public string Password
        {
            get { return this.password; }
            set
            {
                this.password = value;
                NotifyOfPropertyChange(() => Password);
                NotifyOfPropertyChange(() => CanHostGame);
            }
        }

        public bool CanHostGame
        {
            get
            {
                if (!string.IsNullOrWhiteSpace(serverName))
                {
                    if (usePassword)
                        return !string.IsNullOrWhiteSpace(password);
                    return true;
                }
                return false;
            }
        }

        #endregion

        #region Ctor

        public HostGameViewModel()
        {
            this.DisplayName = "Host Game";
            this.ServerName = "BankerenServer";
            this.AllowSpectators = false;
            this.AllowCustomAvatars = true;
            this.UsePassword = false;
            this.Password = null;
        }

        #endregion

        #region Methods

        public void HostGame()
        {
            EventAggregationProvider.EventAggregator.Publish<BankerenEvent>(new BankerenEvent(BankerenEventType.GotoPlayGame));
        }

        public void Back()
        {
            EventAggregationProvider.EventAggregator.Publish<BankerenEvent>(new BankerenEvent(BankerenEventType.GotoMainMenu));
        }

        #endregion
    }
}
